package edu.fsu.cs.SHPE;

import java.net.ConnectException;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class VenueListAdapter extends BaseAdapter {

	private final static String TAG = "SHPE.VenueListAdapter";
	private Context context;
	private ConferenceContainer venueContainer;

	public VenueListAdapter(Context context, String url) throws ConnectException{
		this.context = context;
		venueContainer = new ConferenceContainer(url);
	}

	@Override
	public int getCount() {
		return venueContainer.size();
	}

	@Override
	public Object getItem(int position) {
		return venueContainer.get(position);
	}

	@Override
	public long getItemId(int position) {
		return venueContainer.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		Log.i(TAG, "position " + position);

		LayoutInflater inFlate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
		View v = inFlate.inflate(R.layout.venueitem, null);
		TextView tmp;
		
		Conference tmpConference = venueContainer.get(position);

		if(tmpConference.getImage() != null){
			ImageView image = (ImageView)v.findViewById(R.id.imgPhoto);
			image.setImageDrawable(tmpConference.getImage());
			image.setVisibility(View.VISIBLE);
		}
		
		if(tmpConference.getName() != null){
			tmp = (TextView)v.findViewById(R.id.txtName);
			tmp.setText(tmpConference.getName());
			tmp.setVisibility(TextView.VISIBLE);
		}
		
		/*
		if(tmpConference.getOrganization() != null){
			tmp = (TextView)v.findViewById(R.id.txtOrganization);
			tmp.setText(tmpConference.getOrganization());
			tmp.setVisibility(TextView.VISIBLE);
		}
		
		if(tmpConference.getTitle() != null){
			tmp = (TextView)v.findViewById(R.id.txtTitle);
			tmp.setText(tmpConference.getTitle());
			tmp.setVisibility(TextView.VISIBLE);
		}
		
		if(tmpConference.getStartDate() != null){
			tmp = (TextView) v.findViewById(R.id.txtStartDate);
			tmp.setText(tmpConference.getStartDate() + "- ");
			tmp.setVisibility(TextView.VISIBLE);
		}
		
		if(tmpConference.getEndDate() != null){
			tmp = (TextView) v.findViewById(R.id.txtEndDate);
			tmp.setText(tmpConference.getEndDate());
			tmp.setVisibility(TextView.VISIBLE);
		}
		
		if(tmpConference.getDescription() != null){
			tmp = (TextView)v.findViewById(R.id.txtDescription);
			tmp.setText(tmpConference.getDescription());
			tmp.setVisibility(TextView.VISIBLE);
		}

		
		if(tmpConference.getWebsite() != null){
			tmp = (TextView)v.findViewById(R.id.txtWebsite);
			tmp.setText(tmpConference.getWebsite());
			//Linkify.addLinks(tmp, Linkify.WEB_URLS);
			tmp.setVisibility(TextView.VISIBLE);
		}
		

		
		if(tmpConference.getEmail() != null){
			tmp = (TextView)v.findViewById(R.id.txtEmail);
			tmp.setText(tmpConference.getEmail());
			//Linkify.addLinks(tmp, Linkify.EMAIL_ADDRESSES);
			tmp.setVisibility(TextView.VISIBLE);
		}
		

		
		if(tmpConference.getPhone() != null){
			tmp = (TextView) v.findViewById(R.id.txtPhone);
			tmp.setText(tmpConference.getPhone());
			//Linkify.addLinks(tmp, Linkify.PHONE_NUMBERS);
			tmp.setVisibility(TextView.VISIBLE);
		}
		
		
		if(tmpConference.getRoom() != null){
			tmp = (TextView) v.findViewById(R.id.txtRoom);
			tmp.setText(tmpConference.getRoom());
			tmp.setVisibility(TextView.VISIBLE);
		}
		

		if(tmpConference.getAddress() != null){
			tmp = (TextView)v.findViewById(R.id.txtAddress);
			tmp.setText(tmpConference.getAddress() + ',' + tmpConference.getCity() + ',' + tmpConference.getProvince() + ',' +
					tmpConference.getPostalCode());
			//Linkify.addLinks(tmp, Linkify.MAP_ADDRESSES);
			tmp.setVisibility(TextView.VISIBLE);
		}

	*/

		//ImageButton btn = (ImageButton)v.findViewById(R.id.btnDisplay);
		//btn.setId((int)tmpConference.getId());

		return v;
	}

}
